package com.grf.es.highlevelrest;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.action.update.UpdateResponse;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.query.QueryBuilders;

/**
 * 更新文档
 * @author 郭荣锋
 *
 */
public class Update {
	
	public void update() throws IOException {
		RestHighLevelClient client = Client.getClient();
		UpdateRequest updateRequest = new UpdateRequest("test", "user", "1");
		//updateRequest.index("");
		//updateRequest.type("");
		//updateRequest.id("");
		Map<String, Object> map = new HashMap();
		map.put("userName", "grf");
		map.put("id", "7");
		
		//updateRequest.doc(map);
		updateRequest.doc(XContentFactory.jsonBuilder().startObject()
				.field("userName", "666")
				.field("id", "10")
				.endObject()
				);
		UpdateResponse updateResponse = client.update(updateRequest);
		System.out.println("修改成功");
	}
	
	public static void main(String[] args) throws IOException {
		Update update = new Update();
		update.update();
	}
	
}
